package com.ayg.service;

import com.ayg.mapper.CostMapper;
import com.ayg.pojo.Cost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CostServiceImpl implements CostSerVer{
    @Autowired
    private CostMapper costMapper;


    /**
     * 添加记录
     * @param cost
     */
    @Override
    @Transactional
    public void addCost(Cost cost) {
        cost.setStatus(1);
        costMapper.insert(cost);
    }

    /**
     *
     * 查询记录
     */
    @Override
    public List<Cost> getCost() {

        List<Cost> costList = costMapper.selectList(null);
        return costList;
    }

    @Override
    public Cost getCostById(Integer costId) {
        return costMapper.selectById(costId);
    }


    /**
     * 修改记录
     * @param cost
     */
    @Override
    @Transactional//事物
    public void updateCost(Cost cost) {
        costMapper.updateById(cost);
    }

    @Override
    public void deleteCost(Integer costId) {
        costMapper.deleteById(costId);
    }


}
